<template>
	<view class="main">
		<view class="list" v-if="type == 1">
			<view class="border a">
				<view class="left">
					旧密码
				</view>
				<view class="right">
					<input v-model="oldpassword" type="password" value="" placeholder="请输入密码" />
				</view>
			</view>
			<view class="border a">
				<view class="left">
					新密码
				</view>
				<view class="right">
					<input v-model="newpassword" type="password" value="" placeholder="请确认密码" />
				</view>
			</view>
		</view>
		<view class="list" v-else>
			<view class="border a">
				<view class="left">
					密码
				</view>
				<view class="right">
					<input v-model="newpassword" type="password" value="" placeholder="请输入密码" />
				</view>
			</view>
			<view class="border a">
				<view class="left">
					确认密码
				</view>
				<view class="right">
					<input v-model="conpsd" type="password" value="" placeholder="请确认密码" />
				</view>
			</view>
		</view>
		<view class="btn" v-if="type == 1" @tap="confirm2">
			确认
		</view>
		<view class="btn" v-else @tap="confirm">
			确认
		</view>
	</view>
</template>

<script>
	import {
		send,
		resetpwd2,
		changepwd2
	} from'@/api/index.js'
	export default{
		data(){
			return{
				newpassword:'',
				conpsd:'',
				oldpassword:'',
				newpassword:'',
				type:0
			}
		},
		onLoad(e) {
			if(e.type){
				this.type = e.type
			}
		},
		methods:{
			async confirm2(){
				if(this.oldpassword.length == 0){
					uni.showToast({
						title:'请输入旧密码',
						icon:"none"
					})
					return
				}
				if(this.newpassword.length == 0){
					uni.showToast({
						title:'请输入新密码',
						icon:"none"
					})
					return
				}
				let res = await changepwd2({
					oldpassword:this.oldpassword,
					newpassword:this.newpassword,
				})
				if(res.code == 1){
					uni.showToast({
						title:'修改成功',
						icon:"none"
					})
					setTimeout(()=>{
						uni.navigateBack()
					},1000)
				}else{
					uni.showToast({
						title:res.msg,
						icon:"none"
					})
				}
			},
			async confirm(){
				if(this.newpassword.length == 0){
					uni.showToast({
						title:'请输入密码',
						icon:"none"
					})
					return
				}
				if(this.conpsd.length == 0){
					uni.showToast({
						title:'请确认密码',
						icon:"none"
					})
					return
				}
				if(this.newpassword.length != this.conpsd.length){
					uni.showToast({
						title:'两次密码不一致',
						icon:"none"
					})
					return
				}
				let res = await resetpwd2({
					newpassword:this.newpassword,
				})
				if(res.code == 1){
					uni.showToast({
						title:'设置成功',
						icon:"none"
					})
					setTimeout(()=>{
						uni.navigateBack()
					},1000)
				}else{
					uni.showToast({
						title:res.msg,
						icon:"none"
					})
				}
			},
			finish() {
				this.codeShow = true
			},
			async getCode() {
				if(this.mobile.length == 0){
					uni.showToast({
						title:'请输入手机号',
						icon:"none"
					})
					return
				}
				let res = await send({
					mobile: this.mobile,
					event: 'resetpwd'
				})
				if(res.code == 1){
					uni.showToast({
						title:'发送成功',
						icon:"none"
					})
				}else{
					uni.showToast({
						title:res.msg,
						icon:"none"
					})
				}
				this.codeShow = true
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main{
		min-height: 100vh;
		padding: 100rpx 30rpx;
		color: #000;
		.list{
			.border{
				padding-bottom: 30rpx;
				border-bottom: 2rpx solid #000;
				margin-bottom: 30rpx;
			}
			.a{
				display: flex;
				align-items: center;
				.left{
					width: 25%;
					// font-size: 24rpx;
				}
				.right{
					flex: 1;
					// font-size: 24rpx;
				}
			}
			.b{
				display: flex;
				align-items: center;
				.left{
					width: 25%;
					// font-size: 24rpx;
				}
				.right{
					width: 75%;
					// font-size: 24rpx;
					display: flex;
					align-items: center;
					input{
						flex: 1;
					}
					.codeBtn {
						padding: 10rpx 14rpx;
						background-color: #ea504f;
						color: #fff;
						font-size: 24rpx;
						border-radius: 8rpx;
						margin-left: 6rpx;
						display: flex;
						align-items: center;
					
						::v-deep.u-count-down__text {
							color: #fff;
							font-size: 24rpx;
							line-height: 0;
						}
					}
				}
			}
			.c{
				.left{
					font-size: 28rpx;
					margin-bottom: 40rpx;
				}
				.idList{
					.idItem{
						padding: 16rpx 26rpx;
						border: 2rpx solid #000;
						border-radius: 14rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;
						text{
							color: #666;
							font-size: 24rpx;
						}
						.radio{
							display: flex;
							align-items: center;
							image{
								width: 34rpx;
								height: 34rpx;
							}
						}
					}
				}
			}
		}
		.btn{
			width: 100%;
			padding: 30rpx;
			text-align: center;
			color: #fff;
			background-color: #ea504f;
			border-radius: 10rpx;
		}
	}
</style>